﻿using System;
using System.Drawing;
using System.Diagnostics;
using System.IO;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace is_it_messy
{
    class FileData
    {
        public string FileName => fileName;

        public string Type => type;

        public long Size => size;

        public string AbsolutePath => absolutePath;

        public string RelativePath => relativePath;

        public DateTime LastAccessTime => lastAccessTime;

        public DateTime LastWriteTime => lastWriteTime;

        public Icon Icon => icon;

        private string fileName;
        // 文件后缀  
        private string type;
        private long size;
        private string absolutePath;
        private string relativePath=null;
        private DateTime lastAccessTime;
        private DateTime lastWriteTime;
        private Icon icon;

        public FileData(string abPath)
        {
            FileInfo fileInfo = null;
            try
            {
                fileInfo = new FileInfo(abPath);
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(abPath+"信息获取失败");
            }

            if(fileInfo != null && fileInfo.Exists)
            {
                fileName = fileInfo.Name;
                type = fileInfo.Extension;
                size = fileInfo.Length;
                absolutePath = fileInfo.FullName;
                lastAccessTime = fileInfo.LastAccessTime;
                lastWriteTime = fileInfo.LastWriteTime;
                icon = Icon.ExtractAssociatedIcon(abPath);
                //Image img = icon.ToBitmap();
            }
        }
        
        public FileData(FileInfo fileInfo)
        {
            if(fileInfo != null && fileInfo.Exists)
            {
                fileName = fileInfo.Name;
                type = fileInfo.Extension;
                size = fileInfo.Length;
                absolutePath = fileInfo.FullName;
                lastAccessTime = fileInfo.LastAccessTime;
                lastWriteTime = fileInfo.LastWriteTime;
                icon = Icon.ExtractAssociatedIcon(absolutePath);
                //Image img = icon.ToBitmap();
            }
        }
    }
}
